package com.zjdiepu.www.security.server.sign;

import com.zjdiepu.www.config.ServerConfig;
import com.zjdiepu.www.security.server.core.Partners;
import com.zjdiepu.www.security.sign.ISign;
import com.zjdiepu.www.security.sign.jwt.JwtSignFactory;
import com.zjdiepu.www.security.sign.md5.Md5SignFactory;
import com.zjdiepu.www.security.sign.rsa.RsaSignFactory;
/**
 * 类描述:获取签名工具 <br/>     
 * 项目名称:zjdiepu-client <br/> 
 * 类名称:ServerSignFactory <br/>     
 * 创建人:xiongxiaotun <br/> 
 * 创建时间:2017年8月16日 上午11:42:05  <br/>   
 * 修改人:xiongxiaotun <br/> 
 * 修改时间: 2017年8月16日 上午11:42:05   <br/>  
 * 修改备注:   <br/> 
 * @version V1.0   <br/>
 */
public class ServerSignFactory {
	/**
	 * 获取签名工具
	 * @author xiongxiaotun <br/>
	 * @Title getSign  <br/>
	 * @Description 获取签名工具 <br/>
	 * @param partner
	 * @return
	 * @version V1.0  <br/>
	 */
	public static ISign getSign(Partners partner) {
		ISign sign;
		String signType = ServerConfig.getPartnerSignType(partner);
		if("md5".equals(signType)){
			sign = Md5SignFactory.SIGNLE.getMd5Sign();
		} else if("jwt".equals(signType)){
			sign = JwtSignFactory.SIGNLE.getJwtSign(); 
		} else if("rsa".equals(signType)){
			sign = RsaSignFactory.SIGNLE.getRsaSign();
		} else {
			sign  = Md5SignFactory.SIGNLE.getMd5Sign();
		}
		return sign;
	}
	
	/**
	 * 获取签名秘钥或盐值
	 * @author xiongxiaotun <br/>
	 * @Title getSignSecretKey  <br/>
	 * @Description 获取签名秘钥或盐值 <br/>
	 * @param partner
	 * @return
	 * @version V1.0  <br/>
	 */
	public static String getSignSaltOrSecretKey(Partners partner) {
		String secretKey;
		String signType = ServerConfig.getPartnerSignType(partner);
		if("md5".equals(signType)){
			secretKey = ServerConfig.getPartnerSignMd5SecretKey(partner);
		} else if("jwt".equals(signType)){
			secretKey = ServerConfig.getPartnerSignJwtSecretKey(partner);
		} else if("rsa".equals(signType)){
			secretKey = ServerConfig.getPartnerSignRsaPublicKey(partner);
		} else {
			secretKey = ServerConfig.getPartnerSignMd5SecretKey(partner);
		}
		return secretKey;
	}
}
